﻿
<?php
// print_r($_POST);

  if(!empty($_POST)){
    // print_r($_POST);die;
        $name=$_POST['name'];

        $password=$_POST['password'];

        // $cpassword=$_POST['cpassword'];

        $sex=$_POST['sex'];

         $ID_card=$_POST['ID_card'];

        $address=$_POST['address'];

        $contact_way=$_POST['contact_way'];

        $email=$_POST['email'];

         //链接数据库


        // print_r($_POST);
         $sql = "INSERT INTO `menber`(`name`,`password`,`ID_card`,`sex`,`contact_way`,`address`,`email`) VALUES ('$name','$password','$ID_card','$sex','$contact_way','$address','$email')";

           mysqli_query($link,'set names utf8');

           mysqli_query($link,$sql);

        $xf=mysqli_affected_rows($link);

// print_r($xf);die;

       if($_POST['password']!=$_POST['cpassword']){

             echo '<script>alert("密码不一致");history.go(-1) </script>';

             return false;
       }


       if($xf>0){
                    send_email($email);

               echo '<script>alert("注册成功，请进行邮箱激活！");</script>';

            }else{

        echo '<script>alert("添加失败");history.go(-1) </script>';

      }



  }
   function send_email($to_email){

            header("content-type:text/html;charset=utf-8");
            ini_set("magic_quotes_runtime",0);
            require 'protected/lib/menber/class.phpmailer.php';
            try {
                $mail = new PHPMailer(true); //创建一个邮件发送类对象
                $mail->IsSMTP(); //表示以smtp协议发送邮件
                $mail->CharSet='UTF-8'; //设置邮件的字符编码，这很重要，不然中文乱码
                $mail->SMTPAuth   = true;                  //开启认证
                $mail->Port       = 25;                   //邮件发送服务端口  固定
                $mail->Host       = "smtp.163.com";       //服务器地址
                $mail->Username   = "li277395808@163.com";          //发送人帐号
                $mail->Password   = "asd123456";      //发送人授权码

                $mail->AddReplyTo("li277395808@163.com","mckee");//回复地址 参数1：回复人地址  参数2：昵称
                $mail->From       = "li277395808@163.com"; //发件人邮箱地址
                $mail->FromName   = "中华大大"; //发件人昵称

                $mail->AddAddress($to_email);
                $mail->Subject  = "前台注册功能测试";  //邮箱标题
                $mail->Body = "<h1>phpmail演示</h1>这是php点点通（<font color=red>http://www.iqiyi.com/</font>）对phpmailer的测试内容 <a href='http://localhost/170504/index.php?c=menber&a=email&key=".$to_email."'>点击激活帐号</a>";  //邮箱内容
                // $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; //当邮件不支持html时备用显示，可以省略
                // $mail->WordWrap   = 80; // 设置每行字符串的长度
                //$mail->AddAttachment("f:/test.png");  //可以添加附件
                $mail->IsHTML(true);  //以html格式发送
                $mail->Send();  //发送邮件
                echo '邮件已发送';
            } catch (phpmailerException $e) {
                echo "邮件发送失败：".$e->errorMessage();

        }

     }


 //载入后台公共视图
 // include_once (VIEW_PATH.'home/index/index.html');
 include_once ('protected/View/home/menber/register.html');

?>